package com.kzd.btgame.main.mine

import android.view.LayoutInflater
import androidx.fragment.app.Fragment
import com.kzd.btgame.R
import com.kzd.btgame.callback.AppPagerAdapter
import com.kzd.btgame.databinding.ActivityMineRecordBillBinding
import com.kzd.btgame.main.KEY_RECORD_BILL_INDEX
import com.module.lemlin.app.OwnerStatusBar
import com.module.lemlin.owner.OwnerViewBindingActivity
import java.lang.Exception

class MineRecordBillActivity : OwnerViewBindingActivity<ActivityMineRecordBillBinding>() {

    companion object {
        private val tabs = arrayOf("游戏充值", "平台币充值", "积分")
    }

    private val mAppPagerAdapter: AppPagerAdapter by lazy {
        object : AppPagerAdapter(supportFragmentManager, tabs) {
            override fun fragment(position: Int): Fragment =
                MineRecordBillFragment.newInstance((position + 1))
        }
    }

    private val mIndex: Int
        get() = try {
            (intent?.extras?.getString(KEY_RECORD_BILL_INDEX) ?: "0").toInt()
        } catch (e: Exception) {
            0
        }

    override val inflate: (LayoutInflater) -> ActivityMineRecordBillBinding
        get() = ActivityMineRecordBillBinding::inflate

    override fun initStatusBar(statusBar: OwnerStatusBar) {
        statusBar.run {
            addView = mViewBinding.flMineReckonBar
            barColor = R.color.white
        }
        super.initStatusBar(statusBar)
    }

    override fun initView() {
        mViewBinding.tabMineReckonKind.apply {
            for (item in tabs) {
                addTab(newTab().setText(item))
            }
        }.setupWithViewPager(mViewBinding.vpMineReckonBody.apply {
            adapter = mAppPagerAdapter
        })
        mViewBinding.tabMineReckonKind.getTabAt(mIndex)?.select()

    }
}